<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1250">
    <title></title>
  </head>
  <body>

    <?php
      include "footer.php";
      require 'class/user.class.php';
      
      $new=isset($_POST["vorname"]);
      $fehler=array();
      
      if($new){
   
      	$neuerUser = new User($_POST["e-mail"], $_POST["vorname"], $_POST["nachname"]);
      	$neuerUser->setUser($neuerUser);
      	//header("Location: mailbestaetigung.php");
      }
      
      function check($new,$field){
        
        global $fehler;
        
        if($new){ 
          echo("value='".$_POST[$field]."'"); 
          if($_POST[$field]==""){
            array_push($fehler,$field);
            echo("style='border-color:red;border-width:2px;border-style:solid;'");
          }
        } 
      }
      
    ?>
    
    <div id="fehler"> </div>
  
    <form method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
      <table>
        <tr>
          <td>
            Vorname:
          </td>
          <td>
            <input type="text" maxlength="30" name="vorname" <?php check($new,"vorname"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            Nachname
          </td>
          <td>
            <input type="text" maxlength="30" name="nachname" <?php check($new,"nachname"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            Passwort
          </td>
          <td>
            <input type="password" maxlength="20" name="passwort" <?php check($new,"passwort"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            Passwort wiederholen
          </td>
          <td>
            <input type="password" maxlength="20" name="passwort2" <?php check($new,"passwort2"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            E-Mail Adresse
          </td>
          <td>
            <input type="text" maxlength="255" name="e-mail" <?php check($new,"e-mail"); ?> />
          </td>
        </tr>
        
        <tr>
          <td>
            Stra&szlig;e
          </td>
          <td>
            <input type="text" maxlength="100" name="strasse" <?php check($new,"strasse"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            Hausnummer
          </td>
          <td>
            <input type="text" maxlength="5" name="hausnummer" <?php check($new,"hausnummer"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            Ort
          </td>
          <td>
            <input type="text" maxlength="100" name="ort" <?php check($new,"ort"); ?> />
          </td>
        </tr>
        <tr>
          <td>
            Postleitzahl
          </td>
          <td>
            <input type="text" maxlength="5" name="plz" <?php check($new,"plz"); ?> />
          </td>
        </tr>
        
        <tr>
          <td>
            
          </td>
          <td>
            <input type="submit" />
          </td>
        </tr>
      </table>
    </form>

    <a href="login.php">Doch einloggen</a>

    <script type="text/javascript">
      document.getElementById("fehler").firstChild.nodeValue= 
        <?php 
          
          if(count($fehler)!=0){
            echo("\"Folgende Felder enthalten Fehler: ");
          
          foreach($fehler AS $feld){
            echo($feld).", ";
          }
          echo("\"");
          } else {
            echo("\"\"");
          }
        ?>;
    </script>

    <?php 
    
	/*
	 * 
	 */
	
    $user2 = new User("peter@gmx.de","Peter","Pflaume");
    $users = $user2->getUser();
    
    echo "<pre>";
    print_r($users);    
	echo "</pre>";
    
    ?>

	<table border="1">
	  <tr>
	    <th>E-Mail</th>
	    <th>Vorname</th>
	    <th>Nachname</th>
	  </tr>
	  
	  <?php 
	  
	  foreach($users AS $u){
	  	echo "<tr><td>".$u["Mail"]."</td><td>".$u["Vorname"]."</td><td>".$u["Nachname"]."</td></tr>";
	  }
	  
	  ?>
	  
	</table>

  </body>
</html>